package com.tairanchina.rabbit.listener;

import com.alibaba.fastjson.JSON;
import com.tairanchina.rabbit.entity.User;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;


/**
 * Created by lxliuxuan on 2016/11/24.
 */
@Component("queueMessageListener")
public class QueueMessageListener implements MessageListener {
    @Autowired
    @Qualifier("rabbitTemplate")
    private AmqpTemplate rabbitTemplate;

    @Override
    public void onMessage(Message message) {

        try{

            User user = (User)rabbitTemplate.receiveAndConvert();
            System.out.print(message.toString());
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
